{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-10-26T01:49:38.694182Z",
     "start_time": "2025-10-26T01:49:38.666259Z"
    }
   },
   "source": [
    "a = 1\n",
    "b = 2\n",
    "print(a + b)"
   ],
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-10T15:09:24.090959Z",
     "start_time": "2025-11-10T15:09:24.068017Z"
    }
   },
   "cell_type": "code",
   "source": [
    "money = 1000\n",
    "\n",
    "\n",
    "def work(earn):\n",
    "    global money\n",
    "    money += earn\n",
    "    print(f'赚了{earn}元还剩{money}元')\n",
    "\n",
    "\n",
    "def shop(price):\n",
    "    global money\n",
    "    money -= price\n",
    "    print(f'花了{price}元还剩{money}元')\n",
    "\n",
    "\n",
    "work(100)\n",
    "shop(100)"
   ],
   "id": "5e4d5740ca354804",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "赚了100元还剩1100元\n",
      "花了100元还剩1000元\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-14T15:54:47.959697Z",
     "start_time": "2025-11-14T15:54:47.930234Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def calc_loan(p, n, r, m):\n",
    "    # 请补充代码\n",
    "    per_p = p / n\n",
    "    c = (p - per_p * (m - 1)) * r\n",
    "    return per_p + c\n",
    "\n",
    "\n",
    "# 打印第 10 个月的偿还本息和\n",
    "print(calc_loan(1000000, 360, 0.0041, 10))"
   ],
   "id": "93a8424327f2a5ba",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "6775.277777777778\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-15T14:11:52.114934Z",
     "start_time": "2025-11-15T14:11:52.092964Z"
    }
   },
   "cell_type": "code",
   "source": [
    "get_number = False\n",
    "if get_number:\n",
    "    print('可以买辆新车啦')\n",
    "else:\n",
    "    print('继续等等吧')"
   ],
   "id": "a0d235ab1eeb1fff",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "继续等等吧\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-15T14:15:29.369634Z",
     "start_time": "2025-11-15T14:15:24.723255Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def check_growth(growth):\n",
    "    if growth:\n",
    "        print(f'今日涨粉量：{growth}')\n",
    "    else:\n",
    "        print('你忘记记录今天的涨粉量了')\n",
    "\n",
    "\n",
    "input_growth = input('请输入今日涨分量')\n",
    "check_growth(input_growth)"
   ],
   "id": "cfc78df5632ff722",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "你忘记记录今天的涨粉量了\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "wage_bj = 8500  # 北京薪资\n",
    "wage_hf = 6700  # 合肥薪资\n",
    "rent_bj = 2800  # 北京房租\n",
    "rent_hf = 1400  # 合肥房租\n",
    "if wage_bj - rent_bj > wage_hf - rent_hf:\n",
    "    print('去北京工作吧')\n",
    "else:\n",
    "    print('去合肥工作吧')"
   ],
   "id": "24cd18ac1e79d213"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "distance = int(input('请输入你与“苦力怕”的距离'))\n",
    "if distance <= 3:\n",
    "    print('苦力怕爆炸了')\n",
    "else:\n",
    "    print('暂时安全')"
   ],
   "id": "b284f38c51bd43e"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "answer = input('家里有院子吗：有/没有')\n",
    "if answer == '有':\n",
    "    print('接哈士奇回家')\n",
    "else:\n",
    "    print('还是养别的狗吧')"
   ],
   "id": "3f72878261c6a75b"
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": [
    "def choose_destination(fuel):\n",
    "    # 补全代码\n",
    "    distance = fuel / 8 * 100\n",
    "    if distance >= 472:\n",
    "        print('上海')\n",
    "    elif distance >= 435:\n",
    "        print('北京')\n",
    "    elif distance >= 175:\n",
    "        print('南京')\n",
    "    else:\n",
    "        print('哪也去不了')\n",
    "\n",
    "\n",
    "choose_destination(int(input('请输入剩余油量')))"
   ],
   "id": "281fc2656921f107"
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-16T15:15:24.173773Z",
     "start_time": "2025-11-16T15:15:24.142496Z"
    }
   },
   "cell_type": "code",
   "source": [
    "reward1 = '奖励一台新电脑'\n",
    "reward2 = '奖励一顿油焖虾'\n",
    "reward3 = '奖励一顿胖揍'\n",
    "\n",
    "\n",
    "def choose_reward(math_score, physics_score):\n",
    "    # 补全代码\n",
    "    if math_score >= 75 and physics_score >= 70:\n",
    "        print(reward1)\n",
    "    elif math_score >= 60 and physics_score >= 60:\n",
    "        print(reward2)\n",
    "    else:\n",
    "        print(reward3)\n",
    "\n",
    "\n",
    "# 假设刘星数学考了 76，物理考了 71\n",
    "choose_reward(76, 71)"
   ],
   "id": "b7a0fc65fe6ef3b2",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "奖励一台新电脑\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-16T15:21:19.404441Z",
     "start_time": "2025-11-16T15:21:17.428822Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def guess_password(num):\n",
    "    if num == 666:\n",
    "        print('哼，以为喊我六六六我就能给你开电脑了吗？')\n",
    "    elif num == 768145:\n",
    "        print('密码猜对了，玩一会就去学习吧')\n",
    "    else:\n",
    "        print('密码不正确，快去学习吧')\n",
    "\n",
    "\n",
    "result = int(input('刘星猜测的电脑密码是？：'))\n",
    "guess_password(result)"
   ],
   "id": "a6f51e1970cb161c",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "密码不正确，快去学习吧\n"
     ]
    }
   ],
   "execution_count": 2
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-16T15:23:40.923476Z",
     "start_time": "2025-11-16T15:23:40.892235Z"
    }
   },
   "cell_type": "code",
   "source": [
    "fruits = 'papayaapricotmangopomegranatejackfruitflatpeachblueberrybitterraspberrycoconut'\n",
    "if 'banana' in fruits and 'blueberry' in fruits:\n",
    "    print('不需要补货')\n",
    "elif 'banana' in fruits and 'blueberry' not in fruits:\n",
    "    print('蓝莓需要补货')\n",
    "elif 'banana' not in fruits and 'blueberry' in fruits:\n",
    "    print('香蕉需要补货')\n",
    "else:\n",
    "    print('都需要补货')"
   ],
   "id": "d7d0ef4b010ab31d",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "香蕉需要补货\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-16T15:25:38.264209Z",
     "start_time": "2025-11-16T15:25:34.170668Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def check_year(year):\n",
    "    # 补全代码\n",
    "    if year % 400 == 0 or (year % 4 == 0 and year % 100 != 0):\n",
    "        print('闰年')\n",
    "    else:\n",
    "        print('平年')\n",
    "\n",
    "\n",
    "input_year = int(input('请输入年份：'))\n",
    "check_year(input_year)"
   ],
   "id": "22f77c854124cfb5",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "闰年\n"
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-21T11:56:18.505475Z",
     "start_time": "2025-11-21T11:56:18.468987Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def choose_equipment(HP, AT):\n",
    "    # 补充选择武器的判断\n",
    "    if AT > 1000:\n",
    "        weapon = '苹果炸弹'\n",
    "    else:\n",
    "        weapon = '万能魔杖'\n",
    "\n",
    "    # 补充选择披风的判断\n",
    "    if HP > 800:\n",
    "        cloak = '外婆的红斗篷'\n",
    "    else:\n",
    "        cloak = '高级巫师袍'\n",
    "\n",
    "    print('今天小红帽选择的装备是' + weapon + '和' + cloak)\n",
    "\n",
    "\n",
    "choose_equipment(789, 1435)"
   ],
   "id": "8fd66b2c8db70571",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "今天小红帽选择的装备是苹果炸弹和高级巫师袍\n"
     ]
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-21T12:01:41.311564Z",
     "start_time": "2025-11-21T12:01:41.293895Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def discount(time, is_adventurer):\n",
    "    # 按要求补全代码\n",
    "    if 9 <= time <= 15:\n",
    "        if is_adventurer:\n",
    "            print('冒险者八折')\n",
    "        else:\n",
    "            print('优惠九折')\n",
    "    else:\n",
    "        print('没有优惠')\n",
    "\n",
    "\n",
    "discount(12, True)"
   ],
   "id": "ed86a75a99007ecc",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "冒险者八折\n"
     ]
    }
   ],
   "execution_count": 3
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-21T12:11:42.492680Z",
     "start_time": "2025-11-21T12:11:35.386103Z"
    }
   },
   "cell_type": "code",
   "source": [
    "ending1 = '满足胜利条件，打赢灰狼回家啦'\n",
    "ending2 = '胜败乃兵家常事，小红帽一定会回来的！'\n",
    "ending3 = '三十六计，走为上策！'\n",
    "\n",
    "\n",
    "def game(hp, sp):\n",
    "    print('小红帽外出采蘑菇，遇到了灰狼')\n",
    "    print('当前生命值 hp：' + str(hp))\n",
    "    print('当前魔力值 sp：' + str(sp))\n",
    "    # 请补全代码\n",
    "    # 根据 hp、sp 和用户的选择打印出不同的结局\n",
    "    choice = input('是否要战斗？')\n",
    "    if choice == '是':\n",
    "        if hp >= 900 or sp >= 500:\n",
    "            print(ending1)\n",
    "        else:\n",
    "            print(ending2)\n",
    "    else:\n",
    "        print(ending3)\n",
    "\n",
    "\n",
    "game(800, 700)"
   ],
   "id": "468ca591518284d4",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "小红帽外出采蘑菇，遇到了灰狼\n",
      "当前生命值 hp：800\n",
      "当前魔力值 sp：700\n",
      "满足胜利条件，打赢灰狼回家啦\n"
     ]
    }
   ],
   "execution_count": 4
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-21T12:16:05.746078Z",
     "start_time": "2025-11-21T12:16:05.731084Z"
    }
   },
   "cell_type": "code",
   "source": [
    "def check_test(age, run_50, run_1000):\n",
    "    if age <= 30 and run_50 <= 11 and run_1000 <= 4:\n",
    "        print('达标')\n",
    "    elif age >= 31 and run_50 <= 11.5 and run_1000 <= 4.5:\n",
    "        print('达标')\n",
    "    else:\n",
    "        print('不达标')\n",
    "\n",
    "check_test(19, 10, 3.5)"
   ],
   "id": "cf7b4f5de122b",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "达标\n"
     ]
    }
   ],
   "execution_count": 5
  },
  {
   "metadata": {
    "ExecuteTime": {
     "end_time": "2025-11-21T12:19:37.597976Z",
     "start_time": "2025-11-21T12:19:37.577974Z"
    }
   },
   "cell_type": "code",
   "source": [
    "# 阶梯电价\n",
    "def calc_price(power):\n",
    "    # 补全代码\n",
    "    if power > 200:\n",
    "        return (power - 200) * 0.68 + 150 * 0.51 + 50 *0.48\n",
    "    elif power > 50:\n",
    "        return (power - 50) * 0.51 + 50 *0.48\n",
    "    else:\n",
    "        return power *0.48\n",
    "\n",
    "print(calc_price(134))"
   ],
   "id": "57e82fef4060fe24",
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "66.84\n"
     ]
    }
   ],
   "execution_count": 6
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
